//
//  DDJobDetailCell.m
//  DingDongZP
//
//  Created by Jyh on 16/3/27.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDJobDetailCell.h"
#import "SKTagView.h"

@interface DDJobDetailCell ()

@property (strong, nonatomic) SKTagView *tagView;
@property (strong, nonatomic) UILabel *notiLab;
@property (weak, nonatomic) IBOutlet UIImageView *lineView;



@end

@implementation DDJobDetailCell

- (void)awakeFromNib {
    // Initialization code
    self.detailView.layer.cornerRadius = 5;
    self.detailView.layer.borderColor = COLOR_BORDER_GRAY.CGColor;
    self.detailView.layer.borderWidth = 0.5;
    
    self.jobTitleLabel.text = @"";
    self.jobSalaryLabel.text = @"";
    self.jobTitleContentLabel.text = @"";
    self.locationLabel.text = @"";
    self.experienceLabel.text = @"";
    self.eduLabel.text = @"";
    self.statusImageView.hidden = YES;
}

- (void)updateJobDetailCellWithInfo:(DDJobsDetail *)detailInfo
{
    self.jobTitleLabel.text = detailInfo.jobtitle;
    self.jobSalaryLabel.text = [NSString stringWithFormat:@"￥%@",!detailInfo.salary?@"薪资":detailInfo.salary];
    self.jobTitleContentLabel.text = detailInfo.category;
    self.locationLabel.text = detailInfo.city;
    self.experienceLabel.text = detailInfo.experience;
    self.eduLabel.text = detailInfo.edu;
    
    if ([detailInfo.isverified isEqualToString:@"1"]) {
        // 未通过审核
        self.statusImageView.image = [UIImage imageNamed:@"boss_job_check_failed"];
        self.statusImageView.hidden = NO;
    } else {
        self.statusImageView.hidden = YES;
    }
    
    if ([detailInfo.ishidden isEqualToString:@"1"]) {
        // 隐藏
        self.statusImageView.image = [UIImage imageNamed:@"boss_job_hidden"];
        self.statusImageView.hidden = NO;
    } else {
        self.statusImageView.hidden = YES;
    }
    
    WEAKSELF
    if ([detailInfo.jobskillrequirements count] > 0) {
        if ([detailInfo.jobskillrequirements[0] isKindOfClass:[NSDictionary class]]) {
            
            NSMutableArray *tempArray = [@[] mutableCopy];
            
            for (int i = 0; i < detailInfo.jobskillrequirements.count; i++) {
                
                NSDictionary *tempDic = detailInfo.jobskillrequirements[i];
                [tempArray addObject:[tempDic objectForKey:@"tagtext"]];
            }
            
            [self addTagWithInfoWithArray:tempArray];
            
        } else {
            
            [self addTagWithInfoWithArray:[detailInfo.jobskillrequirements mutableCopy]];
        }
        
        
        [self.contentView addSubview:self.tagView];
        
        [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.detailView.mas_left).offset(5);
            make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(5);
            make.bottom.mas_equalTo(weakSelf.detailView.mas_bottom).offset(-1);
            make.right.mas_equalTo(weakSelf.detailView.mas_right).offset(-1);
//            make.height.mas_equalTo(25);
        }];

    } else {
        
        _notiLab = [[UILabel alloc] init];
        _notiLab.textColor = COLOR_FONT_LIGHT_GRAY;
        _notiLab.font = [UIFont systemFontOfSize:13];
        _notiLab.text = @"未设置标签";
        
        [self.contentView addSubview:_notiLab];
        
        [_notiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.detailView.mas_left).offset(15);
//            make.top.mas_equalTo(weakSelf.detailView.mas_top).offset(60);
            make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(5);
            make.bottom.mas_equalTo(weakSelf.detailView.mas_bottom).offset(-1);
            make.right.mas_equalTo(weakSelf.detailView.mas_right).offset(-1);
//            make.height.mas_equalTo(25);
        }];
    }
}

- (void)addTagWithInfoWithArray:(NSMutableArray *)tagArray
{
    //Add Tags
    if ([tagArray count] > 0) {
        [self.tagView removeAllSubviews];
        
        [tagArray enumerateObjectsUsingBlock:^(NSString *text, NSUInteger idx, BOOL * _Nonnull stop) {
            
            if (text == nil) {
                
                text = @"标签为空";
            }
            
            SKTag *tag = [SKTag tagWithText: text];
        
            tag.textColor = COLOR_FONT_LIGHT_GREEN;
            tag.fontSize = 12;
            tag.padding = UIEdgeInsetsMake(5, 5, 5, 5);
            tag.cornerRadius = 2;
            tag.borderWidth = 1;
            tag.borderColor = COLOR_FONT_LIGHT_GREEN;
            [self.tagView addTag:tag];
        }];
    }
}

- (SKTagView *)tagView {
    if (!_tagView) {
        _tagView = [SKTagView new];
        _tagView.backgroundColor = [UIColor whiteColor];
        _tagView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        _tagView.interitemSpacing = 10;
        _tagView.lineSpacing = 10;
    }
    
    return _tagView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
